#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <set>
#include "tree.h"

using namespace std;

int maxDepth(Tree *root)
{
    if (!root) return 0;
    return 1 + max(maxDepth(root->left), maxDepth(root->right));
}

int minDepth2(Tree *root)
{
    if (!root) return 0;
    int depth =  1 + min(minDepth2(root->left), minDepth2(root->right));
    cout << root->data << " " << depth << endl;
    return depth;
}

int minDepth(Tree *root)
{
    queue<Tree *> myQue;
    myQue.push(root);
    int depth = 1;
    int curLevel = 1, nextLevel = 0;
    while(!myQue.empty()) {
        Tree *top = myQue.front();
        myQue.pop();
        curLevel--;
        if (!top->left && !top->right) break;
        if (top->left) {
            myQue.push(top->left);
            nextLevel++;
        }
        if (top->right) {
            myQue.push(top->right);
            nextLevel++;
        }
        if (curLevel == 0) {
            depth++;
            curLevel = nextLevel;
            nextLevel = 0;
        }
    }
    return depth;
}

int main(int argc, char **argv)
{
    int input[] = {21,7,5,6,3,2,1,4,6,23,43,54,12,54,8,10,11,35,56};
    //int input[] = {7};
    Tree *root = NULL, *root2 = NULL;
    int result;

    for (int i = 0; i < sizeof(input)/sizeof(int); i++) {
        TreeInsert(root, input[i]);
    }
    print_ascii_tree(root);
    //cout << "Max Depth is " << maxDepth(root) << endl;
    cout << "Min Depth is " << minDepth2(root) << endl;
}
